package com.ruanyuan.springboot.dao;

import com.ruanyuan.springboot.pojo.Employee;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 用户表实体类访问层
 */
public interface EmployeeDao {
    /**
     * 通过名称查询用户信息
     * @param username
     * @return
     */
    @Select("SELECT * FROM employee WHERE username=#{username}")
    public Employee selectEmployeeUsername(@Param("username") String username);
    /**
     * 通过id查询用户信息
     * @param
     * @return
     */
    @Select("SELECT * FROM employee WHERE id=#{id}")
    public Employee selectEmployeeid(String id);
    /**
     * 多条件查询用户信息
     */
    @Results(id = "employee" ,value = {
            @Result(property = "id",column = "id"),
            @Result(property = "username",column = "username"),
            @Result(property = "password",column = "password"),
            @Result(property = "age",column = "age"),
            @Result(property = "gender",column = "gender"),
            @Result(property = "Address",column = "Addressid",one = @One(select = "com.ruanyuan.springboot.dao.AddressDao.seleteAddressid")),
            @Result(property = "carCount",column = "id",one = @One(select = "com.ruanyuan.springboot.dao.CarDao.selectCountemployeeid"))
    })
    @Select("SELECT * FROM employee limit #{page},#{limit}")
    public List<Employee> selectEmployee(@Param("page")int page, @Param("limit")int limit);
    /**
     * 多条件查询用户个数
     */
    @Select("SELECT count(*) FROM employee")
    public int selectEmployeeCount();
    /**
     * 添加用户信息
     */
    @Insert("INSERT INTO employee VALUE(NULL,#{username},#{password},#{age},#{gender},#{Address.addid})")
    public int insertEmployee(Employee employee);
    /**
     * 修改用户信息
     */
    @Update("update employee set username=#{username},password=#{password},age=#{age},gender=#{gender},addressid=#{Address.addid} where id=#{id}")
    public int updateEmployee(Employee employee);
    /**
     * 单个删除用户
     */
    @Delete("DELETE FROM employee WHERE id = #{id}")
    public int deleteEmployeeById(String id);
    /**
     * 批量删除用户信息
     */
    @DeleteProvider(type = Batch.class, method = "batchDeleteUser")
    public int deleteEmployeeIds(List<String> empids);
}
